import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  CreateDateColumn,
  Entity,
  OneToMany,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { User } from '../user/user.entity';

@Entity()
export class Position {
  @ApiProperty({ type: Number, description: 'id' })
  @PrimaryGeneratedColumn()
  public id: number;

  @ApiProperty({ type: String, description: '岗位名称' })
  @Column({
    type: 'varchar',
    comment: '岗位名称',
  })
  public name: string;

  @ApiProperty({ type: Number, description: '排序' })
  @Column({
    type: 'int',
    nullable: true,
    comment: '排序',
  })
  public sort: number;

  @ApiProperty({ type: String, description: '状态(1: 正常, 0: 停用)' })
  @Column({
    type: 'varchar',
    nullable: true,
    comment: '状态(1: 正常, 0: 停用)',
  })
  public status: string;

  @ApiProperty({
    type: String,
    description: '备注',
  })
  @Column({
    type: 'text',
    comment: '备注',
    nullable: true,
  })
  public remark: string;

  @ApiProperty({ type: Date, description: '创建时间' })
  @CreateDateColumn({
    type: 'timestamp',
    comment: '创建时间',
    nullable: true,
  })
  public created_date: Date;

  @ApiProperty({
    type: String,
    description: '创建人',
  })
  @Column({
    type: 'varchar',
    length: 20,
    comment: '创建人',
    nullable: true,
  })
  public created_by: string;

  @ApiProperty({ type: Date, description: '更新时间' })
  @UpdateDateColumn({
    type: 'timestamp',
    comment: '更新时间',
    nullable: true,
  })
  public updated_date: Date;

  @ApiProperty({
    type: String,
    description: '更新人',
  })
  @Column({
    type: 'varchar',
    length: 20,
    comment: '更新人',
    nullable: true,
  })
  public updated_by: string;

  @OneToMany(() => User, (user) => user.position)
  users: User[];

  constructor(partial: Partial<Position>) {
    Object.assign(this, partial);
  }
}
